package com.qk.mapper;

import com.qk.entity.Course;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CourseMapper {
    /**
     * 添加课
     */
    @Insert("insert into course(subject, name, price, target, description, create_time, update_time)" +
            " value (#{subject},#{name},#{price},#{target},#{description},#{createTime},#{updateTime})")
    void insert(Course course);

    List<Course> selectList(String name, Integer subject, Integer target);

    /**
     * 根据id查询课
     */
    @Select("select id, subject, name, price, target, description, create_time, update_time from course where id = #{id}")
    Course getById(Integer id);

    /**
     * 更新课
     */
    void update(Course course);

    /**
     * 根据id删除课
     */
    @Delete("delete from course where id = #{id}")
    void deleteById(Integer id);

    /**
     * 根据学科查询课程
     */
    @Select("select id, subject, name, price, target, description, create_time, update_time from course where subject = #{subject}")
    List<Course> listSubject(Integer subject);

    /**
     * 查询所有课程
     */
    @Select("select id, subject, name, price, target, description, create_time, update_time from course")
    List<Course> list();
}
